'''
Demonstration of computing FFT
'''
import sys
sys.path.append("..")
import pyrwi

import scipy as sp
import pylab as pl

t = sp.linspace(0,4,num=2**8)
Fs = 1.0/t[1]
print "Fs = ", Fs

y = sp.ones_like(t) #Start with a DC of 1
print 0, ": ", 1.0 #Report that freq. component

for i in xrange(10,40,10) :
    ampl = 10**(-1*i/10) #Scale amplitudes
    y += ampl*sp.sin(2*sp.pi*i*t) #Add a frequency component
    print i, ": ", ampl #Report this frequency component

#Compute the FFT of the signal
(freq, fy) = pyrwi.analog_fft(Fs, y)

#Plot time domain signal
pl.subplot(2,1,1)
pl.plot(t,y)

#Frequency domain amplitude
#Should see peaks and amplitudes as printed above
pl.subplot(2,1,2)
pl.semilogy(freq, abs(fy))

pl.show()
